
//计划任务
const Admyplan = {
    /**
     * 登陆接口
     * @param data
     * @param url
     * @returns {Promise<any>}
     */
    login: function () {
        return axios({
            url: 'task/task/queryPlanAccordingToTheTask',
            headers: {
                Authorization: "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyTGV2ZWwiOjIsImFkbWluaXN0cmF0aXZlQ29kZSI6IjQ0MDYwNTAxMSIsInVzZXJfaWQiOjEsInVzZXJfbmFtZSI6ImFkbWluIiwic2NvcGUiOlsiYWxsIl0sImxvZ2luTmFtZSI6ImFhYSIsIlVzZXJJZGVudGl0eSI6WyLljLrnrqHnkIblkZgiXSwiZXhwIjoxNjU3MzI1MTI0LCJhdXRob3JpdGllcyI6WyJtZW1iZXI6bWVtYmVyOnVwZGF0ZU1lbWJlclBhc3N3b3JkIiwiZ29vZHM6Z29vZHM6YWRkR29vZHNDYXRlZ29yeSIsImdvb2RzOmdvb2RzOmRlbGV0ZUdvb2RzQ2F0ZWdvcnkiLCJnb29kczpnb29kczphZGRHb29kc0JyYW5kIiwic21zOnN5c25vdGljZXJlY29yZHM6bGlzdCIsInN5czpjb25maWc6c2F2ZSIsInN5czpjb25maWc6dXBkYXRlIiwiZ29vZHM6Z29vZHM6Z2V0U3BlY0FuZEJyYW5rTGlzdCIsImdvb2RzOmdvb2RzOkdvb2RzQ3JlYXRlT3JVcGRhdGUiLCJtZW1iZXI6bWVtYmVyOnVwZGF0ZUN1c3RvbWVyU2VydmljZSIsImdvb2RzOmdvb2RzOnVwZGF0ZUdvb2RzQXR0cmlidXRlIiwic21zOnN5c25vdGljZXRlbXBsYXRlOmxpc3QiLCJzeXM6cm9sZTpsaXN0IiwibWVtYmVyOm1lbWJlcnBhcnRuZXI6YXVkaXRvciIsInN5czptZW51OnNlbGVjdCIsInN1cHBsaWVyOnN1cHBsaWVyOmxpc3QiLCJzeXM6c2NoZWR1bGU6dXBkYXRlIiwic3lzOnNjaGVkdWxlOnNhdmUiLCJtZW1iZXI6bW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XRlSXRlbSIsIm1lbWJlcjptZW1iZXI6cG9pbnRsaXN0IiwiZ29vZHM6Z29vZHM6dXBkYXRlR29vZHNHcm91cCIsInN5czp1c2VyOmluZm8iLCJzeXM6Y29uZmlnOmRlbGV0ZSIsInN5czpzY2hlZHVsZTpydW4iLCJzbXM6c3lzbm90aWNldGVtcGxhdGU6c2F2ZSIsInN1cHBsaWVyOnN1cHBsaWVyOmRlbGV0ZSIsInN5czpyb2xlOmRlbGV0ZSIsIm1lbWJlcjptZW1iZXI6YmFsYW5jZU1lbWJlckFjY291bnQiLCJtZW1iZXI6bWVtYmVyOnVwZGF0ZU1lbWJlckxldmVsIiwic3VwcGxpZXI6c3VwcGxpZXI6c2F2ZSIsImdvb2RzOmdvb2RzOmRlbGV0ZUdvb2RzIiwibWVtYmVyOm1lbWJlcjptZW1iZXJMZXZlbExpc3QiLCJzeXM6c2NoZWR1bGU6cGF1c2UiLCJnb29kczpnb29kczpyZXBseUV2YWx1YXRlQWpheCIsInN5czpsb2c6bGlzdCJdLCJqdGkiOiIwN2IwYjc4Yy03MjAwLTRiY2ItYTFiNy1mYTAxNjFhN2Y0MjMiLCJjbGllbnRfaWQiOiJjbGllbnQifQ.IM3GmWNYgEyZlU6Mfmm3RG4pHMgyqkeAjiEs8BkU8n4"
            },
            params:{
                pageSize:25
            }
        }).then(function (res) {   
           const news=res.data.list  
           var that         
class BiaoDan {
    constructor(id,yeshu,array) {
        that = this
        this.main = document.querySelector(id)
        this.tbody = this.main.querySelector('tbody')
        this.news = array
        this.init(yeshu)
    }
    init(qqq) {
        this.fenye(qqq)
        this.sle()
    }
    sle(){
        this.sel=this.main.querySelector('select')
        this.sel.onclick=(e)=>{
            e.stopPropagation()
            this.main.querySelector(".page ul").innerHTML=''
            let index = this.sel.selectedIndex;
            this.fenye(this.sel.options[index].value) 
        }
    }
    getNode(){
        this.oul=this.main.querySelector(".page ul")
        this.nextPage = this.main.querySelector('.nextPage')
        this.beforePage = this.main.querySelector('.beforePage')
        this.lastPage = this.main.querySelector('.lastPage')
    }
    // 1.导入数据
    // 2 分页功能
    fenye(page){
        that.getNode()
        function daoru(arr) {
            if (typeof arr === "undefined") {
                arr = that.news.slice();
                arr.length = page
            }
            that.tbody.innerHTML = ''
            arr.forEach(function (item) {
                that.tbody.insertAdjacentHTML('beforeEnd', ` <tr>
     <td>${item.id}</td>
     <td>${item.planName}</td>
     <td>${item.planStartTime}</td>
     <td>${item.planEndTime}</td>
     <td>${item.planStatus}</td>
     <td>${item.planRequire}</td>
     <td><div class="btn-group ">
     <button type="button" class="btn btn-sm btn-default amend">
     <span class="glyphicon glyphicon-pencil" > </span>
     </button>
     <button type="button" class="delet btn btn-sm btn-default">
     <span class="glyphicon glyphicon-trash" > </span>
     </button>
     <button type="button" class="sure btn btn-sm btn-default" style="display:none;">
     <span class="glyphicon glyphicon-ok" > </span>
     </button>
     <button type="button" class="back btn btn-sm btn-default" style="display:none;">
     <span class="glyphicon glyphicon-remove" > </span>
     </button>
     </div></td>
 </tr>`)
        })
    }
    daoru()
        let a =1
        function changePage(x, y) {
            let item = that.news.slice((x) * page, +(y) * page)
            daoru(item)
        }
        for (let index = 0; index < that.news.length / page; index++) {
            let oSpan = document.createElement('li');
            oSpan.classList='btn btn-info'
            oSpan.innerHTML = index + 1;       
            oSpan.onclick = function () {
                changePage(this.innerHTML - 1, this.innerHTML)
                a = this.innerHTML
            }        
            that.oul.appendChild(oSpan)
        }
        that.nextPage.onclick = function () {
            if (a == Math.ceil(that.news.length / page)) {
                return 0
            }
            changePage(a, a + 1)
            a++
        }
        that.beforePage.onclick = function () {
            if (a == 1) {
                return 0
            }
            changePage(a - 2, a - 1)
            a--
        }
        that.lastPage.onclick = function () {
            if (that.lastPage.textContent == '最后一页') {
                that.lastPage.textContent = '第一页'
                changePage(Math.ceil(that.news.length / page)-1, Math.ceil(news.length / page))
                a = 4
            } else {
                that.lastPage.textContent = '最后一页'
                changePage(0, 1)
                a = 1
            }
        }
    }
    
}
new BiaoDan(".showone",6,news)

// 表单功能设计
function tables(x, y) {
    var _this
    class Tab {
        constructor(id) {
            _this = this
            this.main = document.querySelector(id);
            this.tbody = this.main.querySelector('tbody');
            this.addTabs = this.main.querySelector('.addTab')
            this.init()
        }
        init() {
            
            this.updateNode()
            this.removeTab()
            this.editTab()
        }
        //1.获取节点
        updateNode() {
            this.tr = this.tbody.querySelectorAll('tr')
            this.amend = this.main.querySelectorAll('.amend')
            this.delet = this.main.querySelectorAll('.delet')
            this.sure = this.main.querySelectorAll('.sure')
            this.back = this.main.querySelectorAll('.back')
        }  
        //2.添加功能
        addTab() {
            this.addTabs.addEventListener('click', function () {
                _this.tbody.insertAdjacentHTML('beforeBegin', y)
                _this.updateNode()
                _this.removeTab()
                _this.editTab()
            })

        }
        //3.删除功能
        removeTab() {
            this.updateNode()
            this.delet.forEach(function (item) {
                item.addEventListener('click', function () {
                    item.parentNode.parentNode.parentNode.remove()
                })
            })

        }
        //4.修改功能
        editTab() {
            this.updateNode()
            let arr = []
            this.amend.forEach(function (item) {
                item.onclick = function () {
                    let tds = this.parentNode.parentNode.parentNode.children
                    $(this).hide().siblings().hide();
                    $(this).siblings(".sure").show()
                    $(this).siblings(".back").show()
                    for (let i = 0; i < tds.length; i++) {
                        if (i != 0 && i != tds.length - 1) {
                            let str = tds[i].textContent
                            arr.push(str)
                            tds[i].innerHTML = `<input type="text" class="form-control"  value="${str}">`
                           // let input = _this.main.querySelector('.input')
                           
                        }
                    }
                }
            })
            //确定功能
            _this.sure.forEach(function (item) {
                item.addEventListener('click', function () {
                    let tds = this.parentNode.parentNode.parentNode.children
                    $(this).hide().siblings().hide();
                    $(this).siblings(".amend").show()
                    $(this).siblings(".delet").show()
                    for (let i = 0; i < tds.length; i++) {
                        if (i != 0 && i != tds.length - 1) {
                            let str = tds[i].children[0].value
                            tds[i].innerHTML = str
                        }
                    }
                })
            })
            //取消功能
            this.back.forEach(function (item) {
                item.addEventListener('click', function () {
                    let tds = this.parentNode.parentNode.parentNode.children
                    $(this).hide().siblings().hide();
                    $(this).siblings(".amend").show()
                    $(this).siblings(".delet").show()
                    for (let i = 0; i < tds.length; i++) {
                        if (i != 0 && i != tds.length - 1) {
                            tds[i].innerHTML = ''
                            tds[i].innerHTML = arr[i - 1]
                        }
                    }
                })
            })

        }
    }
    new Tab(x)
}
tables('.showone')
tables('#mytable')
tables('#mytable2')
tables('#mytable3')
            return Promise.resolve(res)
        }).catch(function (err) {
            console.log(err.txt)
        })
    },
   
}
Admyplan.login()
